//
//  YCGoodDetail3TableViewCell.m
//  lianganyuchu
//
//  Created by iMac on 17/3/2.
//  Copyright © 2017年 杭州桑缇电子商务有限公司. All rights reserved.
//

#import "YCGoodDetail3TableViewCell.h"

@implementation YCGoodDetail3TableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.backView addShadowWith:CGSizeMake(kMainScreen_Width-2*kDistance, 50)];
    
    [self.label1 setFont:[UIFont LightFontOfSize:16]];
    [self.label2 setFont:[UIFont LightFontOfSize:12]];
    [self.label1 setTextColor:TEXT_DEEP];
    [self.label2 setTextColor:TEXT_MIDDLE];
    self.label2.adjustsFontSizeToFitWidth=YES;
    [self.labTotal setFont:[UIFont LightFontOfSize:15]];
    [self.labTotal setTextColor:TEXT_MIDDLE];
    self.labTotal.adjustsFontSizeToFitWidth=YES;
    
    self.buttonConfirm.layer.cornerRadius=2.0f;
    self.buttonConfirm.layer.borderColor=MAIN_COLOR.CGColor;
    self.buttonConfirm.layer.borderWidth=1.0f;
    [self.buttonConfirm.titleLabel setFont:[UIFont LightFontOfSize:14]];
    
    self.restField.layer.borderWidth=1.0f;
    self.restField.layer.borderColor=LINE_COLOR.CGColor;
    self.restField.layer.cornerRadius=2.0f;
    [self.restField setFont:[UIFont LightFontOfSize:15]];
    [self.restField setTextColor:MAIN_COLOR];
    self.restField.keyboardType=UIKeyboardTypeNumberPad;
    self.restField.returnKeyType=UIReturnKeyDone;
    self.restField.delegate=self;
    self.restField.adjustsFontSizeToFitWidth=YES;
    
    UIView * keyboardView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kMainScreen_Width, 50)];
    [keyboardView setBackgroundColor:BACK_COLOR];
    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(kMainScreen_Width-50-kDistance, 0, 50, 50)];
    [button setTitle:@"完成" forState:UIControlStateNormal];
    [button setTitleColor:BLUE_COLOR forState:UIControlStateNormal];
    [button.titleLabel setFont:[UIFont LightFontOfSize:17]];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [keyboardView addSubview:button];
    self.restField.inputAccessoryView =keyboardView;
}
-(void)buttonClicked:(id)sender
{
    [self.restField resignFirstResponder];
    self.saveBlock(self.restField.text,NO);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)btnConfirmClicked:(id)sender
{
    self.saveBlock(self.restField.text,YES);
}

-(void)bindWith:(ItemTable *)item
{
    [self.restField setText:item.stock];
    [self.labTotal setText:[NSString stringWithFormat:@"/%@",item.stock_max]];
    
    if (item.checked.intValue==1) {
        self.buttonConfirm.layer.borderColor=LINE_COLOR.CGColor;
        [self.buttonConfirm setTitleColor:LINE_COLOR forState:UIControlStateNormal];
        self.buttonConfirm.enabled=NO;
    }else{
        self.buttonConfirm.layer.borderColor=MAIN_COLOR.CGColor;
        [self.buttonConfirm setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
        self.buttonConfirm.enabled=YES;
    }
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    UITableView * tableView=(UITableView *)[self  superview];
    [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
    [UIView setAnimationDuration:0.30f];
    tableView.center = CGPointMake(kMainScreen_Width/2, 120);
    [UIView commitAnimations];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    UITableView * tableView=(UITableView *)[self  superview];
    
    [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
    [UIView setAnimationDuration:0.30f];
    tableView.center = CGPointMake(kMainScreen_Width/2, H(tableView)/2);
    [UIView commitAnimations];
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [textField setInputView:nil];
    return YES;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

@end








